package com.sugon.controller.module;

import com.sugon.annotation.AutoLog;
import com.sugon.entity.ModuleTypeEntity;
import com.sugon.service.ModuleTypeService;
import com.sugon.utils.PageUtils;
import com.sugon.utils.Query;
import com.sugon.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 模具类型Controller
 *
 * @author sugon
 * @date 2019-08-06 16:31:41
 */
@Controller
@RequestMapping("moduletype")
public class ModuleTypeController {

    @Resource
    private ModuleTypeService moduleTypeService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("moduletype:list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<ModuleTypeEntity> moduleTypeList = moduleTypeService.queryList(query);
        int total = moduleTypeService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(moduleTypeList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 加载树
     */
    @RequestMapping("/select")
    @ResponseBody
    public R select() {
        return R.ok().put("typeList", moduleTypeService.loadComplexMoldType(null, null, null));
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("moduletype:info")
    @ResponseBody
    public R info(@PathVariable("id") String id) {
        ModuleTypeEntity moduleType = moduleTypeService.queryObject(id);

        return R.ok().put("moduleType", moduleType);
    }

    /**
     * 保存
     */
    @AutoLog("模具类型--保存")
    @RequestMapping("/save")
    @RequiresPermissions("moduletype:save")
    @ResponseBody
    public R save(@RequestBody ModuleTypeEntity moduleType) {
        moduleTypeService.save(moduleType);

        return R.ok();
    }

    /**
     * 修改
     */
    @AutoLog("模具类型--修改")
    @RequestMapping("/update")
    @RequiresPermissions("moduletype:update")
    @ResponseBody
    public R update(@RequestBody ModuleTypeEntity moduleType) {
        moduleTypeService.update(moduleType);

        return R.ok();
    }

    /**
     * 删除
     */
    @AutoLog("模具类型--删除")
    @RequestMapping("/delete")
    @RequiresPermissions("moduletype:delete")
    @ResponseBody
    public R delete(@RequestBody String[] ids) {
        moduleTypeService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<ModuleTypeEntity> list = moduleTypeService.queryList(params);

        return R.ok().put("list", list);
    }
}
